This file contains the stock information of Bitcoin in an hourly basis for Jan 2022 and Feb 2022 from 01/01/2022 to 03/01/2022. Reference dataset from the kaggle.
#libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
%matplotlib inline
#input file
INPUT_FILE_SERIES = "Bitcoin.csv"
series_df = pd.read_csv(INPUT_FILE_SERIES, parse_dates=True, index_col=0)
series_df2 = pd.read_csv(INPUT_FILE_SERIES)
# The function takes the start date, the no of occurence and the frequency as input
def plot_dateXhigh(startdate, period, frequency):
# create a dataframe with the date_range function
range_df = pd.date_range(startdate, periods=period, freq=frequency)
# create a dataframe by locating the date_range against the series_df
range_df = series_df.loc[range_df]
# Find the date against the highest rate
xmax = range_df["high"].idxmax()
# Find the highest rate
ymax = range_df["high"].max()
# Create y axis range
y_axis_low = range_df["high"].min() - 200
y_axis_high = ymax + 200
# **************************************************
# Create plot
plt.figure(figsize=(20,12))
plt.plot(range_df["high"])
# Mark the highest value in the plot
plt.plot(xmax, ymax,"ro")
graph_text = "Maximum Value = " + str(ymax)
plt.text(xmax, ymax+50, graph_text, fontsize=16)
plt.ylim(y_axis_low,y_axis_high)
plt.xlabel("Time", fontsize=16)
plt.ylabel("High value", fontsize=16)
plt.show()
# Plot the highest BTC value on Jan1 2022 hourly for 24 records
plot_dateXhigh("2022-01-01 00:00:00", 24, "1H")
# Plot the highest BTC value from Jan1 2022 daily for 31 records
plot_dateXhigh("2022-01-01 00:00:00", 31, "D")
# Plot the highest BTC value from Jan1 2022 sunday for 5 records
plot_dateXhigh("2022-01-01 00:00:00", 5, "W-SUN")
series_df2['date']=pd.to_datetime(series_df2['date'])
series_df2['date'][0]
Timestamp('2022-03-01 03:43:00')
#close value of the bitcoin on any single day
plt.figure(figsize=(20,12))
plt.plot(series_df2['date'],series_df2['close'])
plt.title('Bitcoin')
Text(0.5, 1.0, 'Bitcoin')
#calculating mean value
series_df2["Mean Low-High"] = (series_df2["high"]+series_df2["low"])/2
fig = px.line(series_df2, x="date", y=["high","Mean Low-High","low"], log_y=True)
fig.update_layout(title=dict(text="Low-High",font=dict(size=22)))
fig.show()